package com.example.springboot_springsecurity_jwt_redis.common;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class Result implements Serializable {
    private static final long serialVersionUID = 1725159680599612404L;

    public Result() {
    }

    /**
     * 成功的返回封装
     * @param message 信息
     * @param data  数据
     * @param jwtToken  jwtToken
     * @param success 状态
     * @return
     */
    public static final Map<String, Object> success(String message, Object data, String jwtToken, Boolean success) {
        Map<String, Object> map = new HashMap();
        map.put("jwtToken", jwtToken);
        map.put("code", ResultCodeEnum.RESULT_CODE_SUCCESS.getCode());
        map.put("message", message);
        map.put("success", success);
        map.put("data", data);
        return map;
    }

    /**
     * 成功的返回封装 data、jwtToken
     * @param data
     * @param jwtToken
     * @return
     */
    public static final Map<String, Object> success(Object data, String jwtToken) {
        Map<String, Object> map = new HashMap();
        map.put("jwtToken", jwtToken);
        map.put("code", ResultCodeEnum.RESULT_CODE_SUCCESS.getCode());
        map.put("message", ResultCodeEnum.RESULT_CODE_SUCCESS.getMessage());
        map.put("data", data);
        map.put("success", true);
        return map;
    }

    /**
     * 成功的无参的返回封装
     * @return
     */
    public static final Map<String, Object> success() {
        Map<String, Object> map = new HashMap();
        map.put("jwtToken", (Object)null);
        map.put("code", ResultCodeEnum.RESULT_CODE_SUCCESS.getCode());
        map.put("message", ResultCodeEnum.RESULT_CODE_SUCCESS.getMessage());
        map.put("data", (Object)null);
        map.put("success", true);
        return map;
    }

    /**
     * 失败的返回封装
     * @param code
     * @param message
     * @param data
     * @return
     */
    public static final Map<String, Object> failure(int code, String message, Object data) {
        Map<String, Object> map = new HashMap();
        map.put("code", code);
        map.put("message", message);
        map.put("data", data);
        map.put("success", false);
        return map;
    }

    /**
     * 失败的返回封装
     * @param code
     * @param message
     * @return
     */
    public static final Map<String, Object> failure(int code, String message) {
        Map<String, Object> map = new HashMap();
        map.put("code", code);
        map.put("message", message);
        map.put("data", (Object)null);
        map.put("success", false);
        return map;
    }

    /**
     * 失败的返回封装
     * @param respCode
     * @param data
     * @param success
     * @return
     */
    public static final Map<String, Object> failure(ResultCodeEnum respCode, Object data, Boolean success) {
        return getStringObjectMap(respCode, data, success);
    }

    /**
     * 失败的返回封装
     * @param respCode
     * @param success
     * @return
     */
    public static final Map<String, Object> failure(ResultCodeEnum respCode, Boolean success) {
        return getStringObjectMap(respCode, success);
    }

    /**
     *
     * @param respCode
     * @param data
     * @param success
     * @return
     */
    public static final Map<String, Object> result(ResultCodeEnum respCode, Object data, Boolean success) {
        return getStringObjectMap(respCode, data, success);
    }

    /**
     *
     * @param respCode
     * @param data
     * @param success
     * @return
     */
    private static Map<String, Object> getStringObjectMap(ResultCodeEnum respCode, Object data, Boolean success) {
        Map<String, Object> map = new HashMap();
        map.put("code", respCode.getCode());
        map.put("message", respCode.getMessage());
        map.put("data", data);
        map.put("success", success);
        return map;
    }

    /**
     *
     * @param respCode
     * @param success
     * @return
     */
    public static final Map<String, Object> result(ResultCodeEnum respCode, Boolean success) {
        return getStringObjectMap(respCode, success);
    }

    /**
     *
     * @param respCode
     * @param success
     * @return
     */
    private static Map<String, Object> getStringObjectMap(ResultCodeEnum respCode, Boolean success) {
        Map<String, Object> map = new HashMap();
        map.put("code", respCode.getCode());
        map.put("message", respCode.getMessage());
        map.put("data", (Object)null);
        map.put("success", success);
        return map;
    }

    /**
     *
     * @param respCode
     * @param jwtToken
     * @param success
     * @return
     */
    public static final Map<String, Object> result(ResultCodeEnum respCode, String jwtToken, Boolean success) {
        Map<String, Object> map = new HashMap();
        map.put("jwtToken", jwtToken);
        map.put("code", respCode.getCode());
        map.put("message", respCode.getMessage());
        map.put("data", (Object)null);
        map.put("success", success);
        return map;
    }
}
